﻿using ContactCenter.Core.ObjectModel;
using FluentNHibernate.Cfg;
using NHibernate.Cfg;

namespace ContactCenter.Persistence.NH.Tasks
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class TaskBase : IConfigurationTask<Configuration>
    {
        private bool _force;

        public TaskBase Force()
        {
            _force = true;
            return this;
        }

        #region Implementation of IOrderable

        public virtual int Position
        {
            get { return int.MinValue; }
        }

        #endregion

        #region Implementation of IConfigurationTask<Configuration>

        public bool CanConfigure()
        {
            return _force ? true : CanConfigureCore();
        }

        public virtual bool CanConfigureCore()
        {
            return true;
        }

        public abstract Configuration Configure(Configuration configuration);

        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    public abstract class FluentTaskBase : TaskBase
    {
        public override Configuration Configure(Configuration configuration)
        {
            return ConfigureCore(Fluently.Configure(configuration)).BuildConfiguration();
        }

        public abstract FluentConfiguration ConfigureCore(FluentConfiguration configuration);
    }
}